package com.study.springsecurity.filter;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 登录验证码拦截器
 * OncePerRequestFilter说明：https://www.cnblogs.com/my-king/p/17730301.html
 *
 * @Author YL
 * @Create 2024/3/30 16:17
 * @Version 1.0
 */
@Slf4j
public class VerificationCodeFilter extends OncePerRequestFilter {
    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
        AntPathRequestMatcher post = new AntPathRequestMatcher("/userLogin", "POST");
        if (post.matches(request)) {
            log.info("验证码拦截器打印验证码：" + request.getParameter("verificationCode"));

        }
        filterChain.doFilter(request, response);
    }
}
